package com.newa.actions;

import java.util.ArrayList;

import org.apache.log4j.Logger;
import org.hibernate.Session;

import com.newa.beans.Section;
import com.newa.dao.DAOSection;
import com.newa.utils.HibUtil;
import com.opensymphony.xwork2.ActionSupport;

public class works extends ActionSupport {
	private Logger LOG = Logger.getLogger(addWork.class);
	private Integer id;
	private Section defSection;
	private Section secById;
	private ArrayList<Section> allSections;

	public String execute() throws Exception {
		Session session = HibUtil.getSessionFactory().openSession();
		DAOSection daos = new DAOSection(session);
		ArrayList<Section> list = daos.getAllSections();
		setAllSections(list);
		try {
			if (id == null||id<1) {
				setDefSection(list.get(0));
			} else {
				setSecById(daos.getSectionById(id));
			}
		} catch (Exception e) {
			LOG.warn(e);
			throw new RuntimeException(e);
		} finally {
			daos.closeSession().close();
		}
		return "success";
	}

	public ArrayList<Section> getAllSections() {
		return allSections;
	}



	public void setAllSections(ArrayList<Section> allSections) {
		this.allSections = allSections;
	}



	public Section getSecById() {
		return secById;
	}



	public void setSecById(Section secById) {
		this.secById = secById;
	}



	public int getId() {
		return (int)id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Section getDefSection() {
		return defSection;
	}

	public void setDefSection(Section defSection) {
		this.defSection = defSection;
	}

}
